package com.diandi.signature.controller.contract;

import com.alibaba.fastjson.JSONObject;
import com.diandi.signature.contract.ContractDataService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by mxp on 2017/12/14.
 */
@Controller
@RequestMapping(value = "/viewContract")
public class ViewContractController {
    private Logger logger = LoggerFactory.getLogger(ViewContractController.class);

    @Autowired
    private ContractDataService contractDataService;

    @RequestMapping(value = "/index")
    public String index(){
        return "contract/viewPage";
    }

    @RequestMapping(value = "/queryList")
    @ResponseBody
    public String queryList(
            @RequestParam(required = false) String step,
            @RequestParam(required = false) String userId,
            @RequestParam(required = false) String contractCode,
            @RequestParam(required = false) String signTimeStart,
            @RequestParam(required = false) String signTimeEnd,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer rows
    ){
        Map<String, Object> queryResult = null;

        if (StringUtils.isNotBlank(step)){
            queryResult = contractDataService.queryList(userId, contractCode, signTimeStart, signTimeEnd, page, rows);
        }

        return JSONObject.toJSONString(queryResult);
    }
}